//**************************************************************************************
// Task Concrete Class File
//**************************************************************************************
// Created On: Sunday, March 06, 2011 as 3:39:48 AM
//**************************************************************************************

using System;
using DevExpress.ExpressApp;
using DevExpress.Xpo;
using DevExpress.Persistent.BaseImpl;

namespace Liekhus.TimeTracker.Module
{
    /// <summary>
    /// The task class represents the core tracking mechanism within the time tracking application.
    /// </summary>
    public partial class Task
    {
        /// <summary>
        /// Executes after the object is constructed so that the defaults can be set.
        /// </summary>
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            
            User user = SecuritySystem.CurrentUser as User;
            if (user != null)
            {
                Owner = Session.GetObjectByKey<User>(user.Oid);
            }
            CreatedOn = DateTime.Now;
        }

        /// <summary>
        /// Executes just prior to the saving so that default values can be set prior to persisting to the database.
        /// </summary>
        protected override void OnSaving()
        {
            base.OnSaving();

            ModifiedOn = DateTime.Now;

            if (Status != null && Status.Code.Equals("F"))
            {
                CompletedOn = DateTime.Now;
            }
        }

        /// <summary>
        /// Executes just prior to deleting so that default values can be persisted.  Remember that data is not removed
        /// but rather marked as invalid in the database.
        /// </summary>
        protected override void OnDeleting()
        {
            base.OnDeleting();
            DeletedOn = DateTime.Now;
        }

        private User _Owner;
        /// <summary>
        /// Represents the current owner of the task.
        /// </summary>
        public User Owner
        {
            get
            {
                return _Owner;
            }
            set
            {
                SetPropertyValue("Owner", ref _Owner, value);
            }
        }
    }
}
